package com.example.bloomfilterdemo;

import cn.hutool.bloomfilter.BitMapBloomFilter;
import com.google.common.hash.BloomFilter;
import com.google.common.hash.Funnels;

/**
 * Created with IntelliJ IDEA 2023.
 * Description:
 * User: homechen
 * Date: 2024-04-06
 * Time: 16:05
 */
public class BloomFilterDemo {
    public static void main(String[] args) {
        BloomFilter<String> filter = BloomFilter.create(Funnels.unencodedCharsFunnel(),
                100000, 0.01); //  10 w 条数据   0.01 的错误率
        filter.put("data1");
        filter.put("data2");
        filter.put("data3");

        System.out.println(filter.mightContain("data1"));
        System.out.println(filter.mightContain("data4"));

        BitMapBloomFilter filter1 = new BitMapBloomFilter(10);
        filter1.add("data1");
        filter1.add("data2");
        filter1.add("data4");

        System.out.println(filter1.contains("data1"));
        System.out.println(filter1.contains("data3"));
    }
}
